﻿using DevExpress.Utils;
using DevTeam;

using System;
using System.Drawing;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class AyrimlarDetay : XPopupForm
    {
        //string OrderRef;
        int AyrimId;
        string tip;
        BindingSource bsAyrim1, bsAyrim2;
        public AyrimlarDetay(int _AyrimId, string _tip)
        {
            InitializeComponent();

            tip = _tip;
            AyrimId = _AyrimId;
            //this.Text = AyrimId.ToString();
        }

        private void AyrimlarDetay_Load(object sender, EventArgs e)
        {



            //bsAyrim1 = new BindingSource(ds, "xAyrim2");
            //bsAyrim2 = new BindingSource(bsAyrim1, "FK_xAyrim3_xAyrim2");


            bsAyrim1 = gvAyrim1.Init("GetAyrimlar4Detay", AyrimId, tip);
            bsAyrim2 = gvAyrim1.AddDetailGrid(gvAyrim2, "ProductId");

            gvAyrim1.MakeColumnInvisible("ProductId");

            //bsAyrim3 = new BindingSource(bsAyrim2, "FK_xAyrim3_xAyrim2");


            //InitGridView(gvAyrim1, bsAyrim1);
            gvAyrim1.AddSummary("KalanQty", "CikanQty", "RezerveQty");
            //gvAyrimlar.Columns["TalepTarihi"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            //gvAyrim.Columns["TalepTarihi"].DisplayFormat.FormatString = "g"; //G
            //gvAyrimlar.ActiveFilterString = "stCikisId <> 'Çıkıldı'";

            //InitGridView(gvAyrim2, bsAyrim2);
            gvAyrim2.Columns["AlternatifId"].Caption = "OrgProductId";

            gvAyrim1.OptionsBehavior.Editable =
            gvAyrim2.OptionsBehavior.Editable = false;

            //RefreshData();

            splitContainerControl1.AutoSize();
            //bsAyrim3.Filter = "OrderRef=" + intParse(bsAyrim2, "OrderRef").ToString() + " AND ProductId=" + intParse(bsAyrim2, "ProductId").ToString();

            gvAyrim1.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gvAyrim1_RowCellStyle);
            gvAyrim2.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gvAyrim2_RowCellStyle);

            bsAyrim1.Filter = "KalanQty>0";
            checkEdit1.CheckedChanged += checkEdit1_CheckedChanged;
            checkEdit1.Checked = true;

            //gvAyrim1.FocusedRowHandle = gvAyrim1.LocateByValue(0, gvAyrim1.Columns["ProductId"], ProductId);
            gvAyrim1.BestFitColumns();
            gvAyrim2.BestFitColumns();
        }

        void checkEdit1_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            bsAyrim1.Filter = checkEdit1.Checked ? string.Empty : "KalanQty>0";
        }

        void gvAyrim1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            switch (e.Column.FieldName)
            {
                case "KalanQty":
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                    break;
                default:
                    break;
            }
        }

        void gvAyrim2_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            switch (e.Column.FieldName)
            {
                case "Qty":
                    if (intParse(gvAyrim2.GetRowCellValue(e.RowHandle, "ShelfId")) > 1)
                        e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                    break;
                default:
                    break;
            }

        }


    }
}